package demo

object Scala_Exec {

  var l1 = List(("bj", 15000), ("sh", 13000), ("bj", 9800), ("sh", 16000))

  var l2 =List("hello 1909","hello spark","hello 1909")
  //要求操作l1，返回按照薪资降序排序后的结果
  var res1 = l1.sortBy(x => -x._2)
  def main(args: Array[String]): Unit = {
    println(res6)
  }

  //计算出上海地区的平均薪资
  var res2 = l1.filter(x => x._1.equals("sh")).map(x=>x._2)

  var res3 = res2.sum/res2.length

  //返回北京地区最高的薪资
  var res4 = l1.filter(x => x._1.equals("bj")).sortBy(x=>x._2).head


  //统计出l2中每个单词出现的频次
  var res5 = l2.flatMap(x => x.split(" ")).groupBy(w => w).map(x=>(x._1,x._2.length))

  var res6 = l2.flatMap(x=>x.split(" ")).map(word=>(word,1))
    .groupBy(x=>x._1).mapValues(x=>x.map(x=>x._2).reduce(_ + _))


}
